<?php
namespace app\api\model\v1;

/*
 * content : 用户判断类
 * Author  : Songyicong
 * time    : 2018-04-19 10:41:29
 * email   : m13726262373@163.com
 */

use app\api\model\BaseModel;
use think\Cache;

class User extends BaseModel{

    protected $table = "km_user";

    /** 通过union_id 查询用户信息 */
    public static function getUnionUser($union = ""){
        if(empty($union)){
            return false;
        }
        $where['wechat_union_id'] = $union;
        $results = self::where($where)->find();
        return empty($results)?false:$results->toArray();
    }

    /** 通过用户名查询用户信息 */
    public static function getLoginUser($login = ""){
        if(empty($login)){
            return false;
        }
        $where['login_name'] = $login;
        $results = self::where($where)->find();
        return empty($results)?false:$results->toArray();
    }

    public static function isRegistEmail($email=""){
        if(empty($email)){
            return false;
        }
        
        $where['email'] = $email;
        $results = self::where($where)->find();
        return empty($results)?false:$results->toArray();
    }

    public static function isRegistLoginName($login=""){
        if(empty($login)){
            return false;
        }
        $where['login_name'] = $login;
        $results = self::where($where)->find();
        return empty($results)?false:$results->toArray();
    }

    /** 判断邮件是否验证 */
    public static function isEmailState($email = ""){
        $flag = false;
        if(empty($email)){
            return $flag;
        }
        $where['email'] = $email;
        $results = self::where($where)->find();
        $flag = empty($results)?false:$results->toArray();
        
        if($flag && substr($flag['state'], 0, 1) == 1){
            $flag = true;
        }
        return $flag;
    }
    
}
